package cn.takovh.zpl.bean;

import org.dom4j.Attribute;
import org.dom4j.Element;

import java.util.Iterator;

public class Meta implements ElementBean {
    private String name;
    private String content;

    public Meta() {
    }

    public Meta(String name, String content) {
        this.name = name;
        this.content = content;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public void getElement(Element root) {
        root.addAttribute("name", name);
        root.addAttribute("content", content);
    }

    @Override
    public void parseElement(Element root) {

        for (Iterator<Attribute> it = root.attributeIterator(); it.hasNext(); ) {
            Attribute attribute = it.next();
            String name = attribute.getName();
            String value = attribute.getValue();
            switch (name) {
                case "name":
                    this.name = value;
                    break;
                case "content":
                    this.content = value;
                    break;
                default:
                    throw new IllegalArgumentException(name);
            }
        }
    }
}
